package com.qf.mapper;

import com.qf.domain.Student;
import com.qf.domain.Student2;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface StudentMapper2 {

    /**
     * 查询所有学生信息的接口方法
     * @return
     */
    @Select("select * from student")
    @ResultMap("stu2Map") //利用stu2Map这个手动映射，封装结果
    List<Student2> findAll();

    @Select("select * from student where id=#{id}")
    Student findById(Integer id);

    @Select("select * from student where name=#{name} and age=#{age}")
    Student findByNameAndAge(@Param("name") String name,@Param("age") Integer age);

    @Insert("insert into student (name,age,insert_time) values (#{name},#{age},#{insertTime})")
    //可选配置，如果需要获取新增记录后的自增主键值，我们就可以添加这个注解
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    int insert(Student stu);

    @Delete("delete from student where id=#{id}")
    int delete(Integer id);

    @Update("update student set name=#{name},age=#{age},insert_time=#{insertTime} where id=#{id}")
    int update(Student stu);

    List<Student> findByIds(Integer... ids);

}
